home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Reference & Presen…tion Library 2 (Reseller)
/
Apple R&P Lib Reseller v2.0.iso
/
3-Demos
/
HyperCard Demos
/
HyperCard In Education
/
Towers of Hanoi
/
background_2783.txt
< prev
next >
Wrap
Text File
|
1989-07-14
|
10KB
|
399 lines
-- background: 2783 from stack: in
-- bmap block id: 2216
-- flags: 0000
-- background id: 0
-- name:
----- HyperTalk script -----
-- Copyright © 1988 Cincinnati Country Day School. All rights reserved.
-- For information, contact Joseph F. Hofmeister, Computer Coordinator
-- The HyperSchool, Cincinnati Country Day School
-- 6905 Given Road, Cincinnati, Ohio 45243
-- Telephone 513-561-7298 AppleLink K0197
on openStack
if the version < 1.2 then
answer "This stack needs HyperCard version 1.2."
set lockMessages to true
domenu home
else
hide message
reset paint
initTower
setTower 2
end if
end openStack
on closeStack
reset paint
end closeStack
on initTower
global maxDisks, nDisks, yBase, dHeight, xPole, poleTop
put 7 into maxDisks
put the number of bkgnd buttons - 7 into nDisks
put 250 into yBase
put 20 into dHeight
put "0,0,0" into xPole
get round( width of card window / 2 )
put it - 150 into item 1 of xPole
put it into item 2 of xPole
put it + 150 into item 3 of xPole
put yBase - round( 7.5 * dHeight ) - 4 into poleTop
end initTower
on makeBase
global yBase, dHeight, xPole, poleTop
set the editBkgnd to true
choose select tool
drag from 0,0 to width of card window, height of card window
doMenu "Clear Picture"
choose round rect tool
set the filled to true
set the pattern to 22
put poleTop + 4 + round( dHeight / 2 ) into t
put yBase + dHeight into b
repeat with i = 1 to 3
get item i of xPole
drag from it - 5, t to it + 5, b
end repeat
set the pattern to 20
get yBase + round( dHeight / 2 )
drag from item 1 of xPole - 90, it to item 3 of xPole + 90, it + round( 1.5 * dHeight )
reset paint
choose browse tool
end makeBase
on deleteTower
global nDisks
choose button tool
set the editBkgnd to true
repeat with i = the number of bkgnd buttons down to 8
if the name of bkgnd button i contains "Disk" then
click at the loc of bkgnd button i
doMenu "Clear Button"
end if
end repeat
choose browse tool
put 0 into nDisks
end deleteTower
on makeTower height, dest
global nDisks, yBase, dHeight, xPole
global firstPole, stackHeight
deleteTower
set the editBkgnd to true
put height into nDisks
put dest into firstPole
put "0,0,0" into stackHeight
put nDisks into item firstPole of stackHeight
put item firstPole of xPole into thisPole
put yBase - dHeight * ( nDisks - 1 ) into yDisk
put 60 into dWidth
repeat with i = 1 to nDisks
doMenu "New Button"
get "Disk" && i
set the name of bkgnd button "New Button" to it
set the width of bkgnd button it to dWidth
set the height of bkgnd button it to dHeight
set the loc of bkgnd button it to thisPole, yDisk
add 10 to dWidth
add dHeight to yDisk
end repeat
choose browse tool
put 0 into field depth
put 0 into field moves
end makeTower
on setTower dest
global nDisks, yBase, dHeight, xPole
global firstPole, stackHeight
put dest into firstPole
put "0,0,0" into stackHeight
put nDisks into item firstPole of stackHeight
put item firstPole of xPole into thisPole
put yBase - dHeight * ( nDisks - 1 ) into yDisk
repeat with i = 1 to nDisks
get "Disk" && i
set the loc of bkgnd button it to thisPole, yDisk
add dHeight to yDisk
end repeat
put 0 into field depth
put 0 into field moves
end setTower
on shiftTower dest
global nDisks, firstPole
put 0 into field depth
put 0 into field moves
choose button tool
moveTower nDisks, firstPole, dest, 6 - firstPole - dest
put dest into firstPole
choose browse tool
end shiftTower
-- part 7 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=151 top=61 right=83 bottom=239
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Set Tower
----- HyperTalk script -----
on mouseUp
answer "Disks on which pole?" with "Left" or "Center" or "Right"
if it = "Right" then
setTower 3
else
if it = "Center" then
setTower 2
else
setTower 1
end if
end if
end mouseUp
-- part 8 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=243 top=61 right=83 bottom=331
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Move Tower
----- HyperTalk script -----
on mouseUp
answer "Move to which pole?" with "Left" or "Center" or "Right"
if it = "Right" then
shiftTower 3
else
if it = "Center" then
shiftTower 2
else
shiftTower 1
end if
end if
end mouseUp
-- part 9 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=105 top=24 right=57 bottom=407
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 3
-- text size: 18
-- style flags: 2048
-- line height: 24
-- part name: Tower of Hanoi
----- HyperTalk script -----
on mouseUp
if the visible of card field Help is true then
set the visible of card field "Help" to false
else
set the visible of card field Author to true
set the visible of card button OK to true
end if
end mouseUp
-- Answers to the questions posed in the "Help" field:
-- If n is the number of disks in the stack, the maximum depth of
-- recursion is n, and the total number of moves is 2^n - 1.
-- By the way, this means that the Tibetan monks have their work cut
-- out for them with a stack of 100 disks. Even if they were using
-- a Cray supercomputer, and could make one move per nanosecond,
-- completion of the task would still take about 3000 times the
-- present age of the universe.
-- part 18 (button)
-- low flags: 00
-- high flags: 0001
-- rect: left=126 top=315 right=339 bottom=161
-- title width / last selected line: 0
-- icon id / first selected line: 25002 / 25002
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Help
----- HyperTalk script -----
on mouseUp
set the visible of card field Help to not visible of card field Help
end mouseUp
-- part 49 (field)
-- low flags: 01
-- high flags: 0001
-- rect: left=114 top=296 right=311 bottom=229
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 65535
-- font id: 2
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: depthLabel
-- part 50 (field)
-- low flags: 01
-- high flags: 0002
-- rect: left=229 top=296 right=311 bottom=254
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 2
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: depth
-- part 52 (field)
-- low flags: 01
-- high flags: 0002
-- rect: left=258 top=296 right=311 bottom=283
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 2
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: moves
-- part 53 (field)
-- low flags: 01
-- high flags: 0001
-- rect: left=283 top=296 right=311 bottom=398
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 2
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: moveLabel
-- part 60 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=59 top=61 right=83 bottom=147
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Make Tower
----- HyperTalk script -----
on mouseUp
global maxDisks
get -1
repeat while it < 0 or it > maxDisks
ask "How many disks (0 -" && maxDisks & ")?"
if it is empty then exit mouseUp
get round( it )
end repeat
makeTower it, 1
end mouseUp
-- part 61 (button)
-- low flags: 00
-- high flags: A004
-- rect: left=335 top=61 right=83 bottom=453
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: See Algorithm
----- HyperTalk script -----
on mouseUp
edit script of this stack
end mouseUp
-- part 85 (button)
-- low flags: 00
-- high flags: 8003
-- rect: left=226 top=200 right=220 bottom=286
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Disk 1
-- part 95 (button)
-- low flags: 00
-- high flags: 8003
-- rect: left=221 top=220 right=240 bottom=291
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Disk 2
-- part 96 (button)
-- low flags: 00
-- high flags: 8003
-- rect: left=216 top=240 right=260 bottom=296
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Disk 3
-- part 97 (button)
-- low flags: 00
-- high flags: 8003
-- rect: left=61 top=240 right=260 bottom=151
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Disk 4